package edu.gatech.cc.CFAWaffleFriesWheresMyStuff.common;

import java.util.List;

/**
 * An interface that manages the list of users.
 * @author Michael Luke Hawkins
 */
public interface Datastore {
	/**
	 * Saves the given user in the database.
	 * If the given username is already registered, the existing account data is overwritten with the given data.
	 * If the given username is not registered, a new record is added to the database.
	 * @param user The user data to save.
	 */
     void saveUser(User user);
     
     /**
 	 * Saves the given admin in the database.
 	 * If the given username is already registered, the existing account data is overwritten with the given data.
 	 * If the given username is not registered, a new record is added to the database.
 	 * @param admin The admin data to save.
 	 */
     void saveAdmin(Admin admin);
     
     /**
      * Deletes the record for the given username from the database.
      * @param deletingName username to be deleted
      * @param adminName admin performing the deletion
      * @throws UserDoesNotExistException Thrown is the username cannot be found
      * @throws UserIsNotAdminException Thrown if the given admin name is not the username of an admin
      * @throws CanNotDeleteSelfException Thrown if the admin attempts to delete its own account
      */
     void deleteUser(String deletingName, String adminName) throws UserDoesNotExistException, UserIsNotAdminException, CanNotDeleteSelfException;
     
     /**
      * Checks if the given username is already registered.
      * @param username The username to check for
      * @return True if the user is registered, false if the username is not in the database.
      */
     boolean userExists(String username);
     
     /**
      * Checks if the given username is associated with an admin account
      * @param username The username to check
      * @return True if the user's accound has admin rights, false otherwise
      */
     boolean checkAdmin(String username);
     
     /**
      * Gets the user data for the given username from the database.
      * @param name the username to get data for
      * @return A User or Admin object populated with the appropriate data
      * @throws UserDoesNotExistException Thrown if the given username cannot be found.
      */
     User getUser(String name) throws UserDoesNotExistException;
     
     /**
      * Gets the list of all usernames in the database.
      * @return list of all usernames in the database.
      */
     List<String> getAllUsernames();
     
     /**
      * Marks the lock status of the given user as false in the database.
      * @param user the username of the user to modify
      * @throws UserDoesNotExistException Thrown if the given username cannot be found
      */
     void unlock(String user) throws UserDoesNotExistException;
     
     /**
      * Marks the admin status of the given user as true in the databse.
      * @param username The username of the account to modify
      * @throws UserDoesNotExistException Thrown if the given username cannot be found.
      */
     void turnUserToAdmin(String username) throws UserDoesNotExistException;
     
     /**
 	 * Saves the given item in the database.
 	 * If the given item is already stored, the existing item data is overwritten with the given data.
 	 * If the given item is not stored, a new record is added to the database.
 	 * @param item The item data to save.
 	 */
     void saveItem(Item item);
     
     /**
      * Gets the item with the given id.
      * @param id ID for the desired item.
      * @return The item with the given ID.
     * @throws ItemDoesNotExistException Thrown if there is no item with the given ID.
      */
     Item getItem(int ID) throws ItemDoesNotExistException;
     
     /**
      * Checks if there is an item with the given ID saved in the database.
      * @param ID the ID to search for.
      * @return true if the ID is found, false otherwise
      */
     boolean itemExists(int ID);
     
     /**
      * Gets a list of all items associated with the given user
      * @param username The username to search for
      * @return The list of items for the given username.
      */
     List<Item> getUserItems(String username);
     
     /**
      * Gets a list of all items that meet the given search criteria
      * @param type The type value to search for
      * @param openStatus The open status to search for
      * @param category The category value to search for
      * @param name The name to search for
      * @param date The date to search after
      * @param location The location to search for
      * @return A list of items for the given search criteria
      */
     List<Item> filterItems(String type, Boolean openStatus, String category, String name, Long date, String location, String username);
     
     /**
      * Gets the next ID to be assigned to an item in the database.
      * @return The biggest item ID in the database plus one.
      */
     Integer getNextItemID();
     
     class UserDoesNotExistException extends Exception {
    	 	private static final long serialVersionUID = 1L;
     }
     class UserIsNotAdminException extends Exception {
  	 	private static final long serialVersionUID = 1L;
     }
     class CanNotDeleteSelfException extends Exception {
 	 	private static final long serialVersionUID = 1L;
     }
     class ItemDoesNotExistException extends Exception{
		private static final long serialVersionUID = 1L;
     }
}
